<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3_类中的方法this指向</title>
</head>
<body>
  <script>
    class Person {
      constructor(name, age) {
        this.name = name
        this.age = age
      }
      speak() {
        // 'use strict' // 类中的方法默认开启了局部的严格模式
        console.log(this)
      }
    }
    const p1 = new Person('Tom', 18)
    p1.speak() // 通过实例调用speak方法

    const x = p1.speak
    x() // 这里的this是undefined
  </script>
</body>
</html>